#include "UnitTest++.h"
#include <zlib.h>
#include <cassert>
#include <fstream>
#include <iostream>
using namespace std;


TEST (Z_compress)
{
	unsigned char data[256];
	for (int i = 0; i < 256; i++) {
		data[i] = i;
	}

	long  size = compressBound (256);
	char* buf  = new char[size];
	
	int ret = compress ((Bytef*)buf,
						(uLongf*)&size,
						data,
						sizeof(data));
	CHECK_EQUAL (Z_OK, ret);

	ofstream ofs ("compressed.bin", ios::binary);
	CHECK_EQUAL (true, (bool)ofs);

	ofs.write (buf, size);
	ofs.close ();

}

TEST (Z_uncompress)
{
	ifstream ifs ("compressed.bin", ios::binary);
	CHECK_EQUAL (true, (bool)ifs);

	ifs.seekg (0, ios::end);
	int fsize = ifs.tellg ();
	ifs.seekg (0, ios::beg);

	char* fdata = new char[fsize];
	ifs.read (fdata, fsize);

	unsigned char buf[256];
	long size = 256;

	int ret = uncompress ((Byte*)buf,
							(uLongf*)&size,
							(Byte*)fdata,
							(uLong)fsize);

	CHECK_EQUAL (Z_OK, ret);

	for (int i = 0; i < 256; i++) {
		CHECK_EQUAL (i, (int)buf[i]);
	}

	ifs.close();

}